<template>
	<view class="report-check">
		<view class="report-check-img">

			<image src="../../static/xls.png" mode="" v-if="fileType=='xlsx'"></image>
			<image src="../../static/pdf.png" mode="" v-if="fileType=='pdf'"></image>
			<image src="../../static/img.png" mode="" v-if="fileType=='img'"></image>
			<image src="../../static/doc.png" mode="" v-if="fileType=='docx'"></image>
			<image src="../../static/TXT.png" mode="" v-if="fileType=='txt'"></image>
		</view>
		<view class="report-check-fileName">{{fileName}}</view>
		<!-- <view class="report-check-content">
			{{text}}
		</view> -->
		<view class="report-check-preview" @click="reviewFile">
			在线预览
		</view>
		<view class="report-check-download" @click="downloadFile">
			复制链接下载
		</view>
	</view>
</template>


<script>
		import imgUrl from '../../utils/imgUrl.js'
	export default {
		data() {
			return {
				fileUrl:'',
				fileName: "",
				fileType:'pdf'
			};
		},
		onLoad(options) {
			console.log("url",options.fileUrl)
			console.log("name",options.fileName)
			this.fileName = options.fileName
			this.fileUrl = options.fileUrl
		},
		methods:{
			// 预览
			reviewFile(){
				let that = this
				uni.downloadFile({
				  url: imgUrl + that.fileUrl,
				  // url: "http://192.168.82.130:8090/files/secure/20230112/bdf8be05e0b560d534b4a8fbe3dad52d/S221100001-D20230100017-P0003.pdf",
				  success: function (res) {
					  console.log('res',res)
				    var filePath = res.tempFilePath;
				    uni.openDocument({
				      filePath: filePath,
				      success: function (res) {
				      }
				    });
				  },
				  fail:function(res){
				  }
				});
			},
			//下载
			downloadFile(){

				wx.setClipboardData({
				  data: imgUrl + this.fileUrl,
				  success (res) {
				    wx.getClipboardData({
				      success (res) {
				        uni.showToast({
				        	title: '复制成功,请在浏览器中打开',
				        	duration: 2000,
				        	icon: 'none'
				        });
				      }
				    })
				  }
				})
			}
		}
	}
</script>

<style lang="scss">
	.report-check{
		width: 100vw;
		height: 100vh;
		display: flex;
		flex-direction: column;
		font-size: 32rpx;
		background-color: #fff;
		align-items: center;
		&-img{
			width: 100%;
			display: flex;
			justify-content: center;
			margin:20rpx 0;
			image{
				width: 100rpx;
				height: 100rpx;
			}
		}
		&-content{

			margin:20rpx;
		}
		&-preview{
			width: 70%;
			height: 70rpx;
			border: 1px solid #ccc;
			display: flex;
			align-items: center;
			justify-content: center;
			margin: 20rpx 0;
			border-radius: 10rpx;
		}
		&-download{
			width: 70%;
			height: 70rpx;
			background-color: #0f90d1;
			color: #fff;
			display: flex;
			align-items: center;
			justify-content: center;
			border-radius: 10rpx;
		}
	}
</style>
